package com.cdz.web.controller.bus;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.cdz.common.annotation.Log;
import com.cdz.common.core.controller.BaseController;
import com.cdz.common.core.domain.AjaxResult;
import com.cdz.common.enums.BusinessType;
import com.cdz.bus.domain.BusStation;
import com.cdz.bus.service.IBusStationService;
import com.cdz.common.utils.poi.ExcelUtil;
import com.cdz.common.core.page.TableDataInfo;

/**
 * 充电站Controller
 * 
 * @author guyi
 * @date 2024-11-19
 */
@RestController
@RequestMapping("/bus/busStation")
public class BusStationController extends BaseController
{
    @Autowired
    private IBusStationService busStationService;

    /**
     * 查询充电站列表
     */
    @PreAuthorize("@ss.hasPermi('bus:busStation:list')")
    @GetMapping("/list")
    public TableDataInfo list(BusStation busStation)
    {
        startPage();
        List<BusStation> list = busStationService.selectBusStationList(busStation);
        return getDataTable(list);
    }




    /**
     * 导出充电站列表
     */
    @PreAuthorize("@ss.hasPermi('bus:busStation:export')")
    @Log(title = "充电站", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, BusStation busStation)
    {
        List<BusStation> list = busStationService.selectBusStationList(busStation);
        ExcelUtil<BusStation> util = new ExcelUtil<BusStation>(BusStation.class);
        util.exportExcel(response, list, "充电站数据");
    }

    /**
     * 获取充电站详细信息
     */
    @PreAuthorize("@ss.hasPermi('bus:busStation:query')")
    @GetMapping(value = "/{stationId}")
    public AjaxResult getInfo(@PathVariable("stationId") String stationId)
    {
        return success(busStationService.selectBusStationByStationId(stationId));
    }

    /**
     * 新增充电站
     */
    @PreAuthorize("@ss.hasPermi('bus:busStation:add')")
    @Log(title = "充电站", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody BusStation busStation)
    {
        return toAjax(busStationService.insertBusStation(busStation));
    }

    /**
     * 修改充电站
     */
    @PreAuthorize("@ss.hasPermi('bus:busStation:edit')")
    @Log(title = "充电站", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody BusStation busStation)
    {
        return toAjax(busStationService.updateBusStation(busStation));
    }

    /**
     * 删除充电站
     */
    @PreAuthorize("@ss.hasPermi('bus:busStation:remove')")
    @Log(title = "充电站", businessType = BusinessType.DELETE)
	@DeleteMapping("/{stationIds}")
    public AjaxResult remove(@PathVariable String[] stationIds)
    {
        return toAjax(busStationService.deleteBusStationByStationIds(stationIds));
    }

    /**
     * 同步数据到本系统
     */
    @PreAuthorize("@ss.hasPermi('bus:busStation:edit')")
    @GetMapping("/syncStationData")
    public AjaxResult syncStationData() throws Exception {
        busStationService.syncStationData();
        return AjaxResult.success();
    }
}
